<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%  %>
<jsp:include page="head.jsp" />

<jsp:include page="header.jsp" />
<% 
String un = request.getParameter("uname");
String pw = request.getParameter("passwd");

//Mike Earl
//declare variables for customer info that will be used in the HTML;
String firstName = null;
String lastName = null;
String address = null;
String city = null;
String prov = null;
String postal = null;
String country = null;
String homePhone = null;
String busPhone = null;
String email = null;
String password = null;
String bookingNo = null;
String bookingDate = null;
String travellerCount = null;
Connection conn = null;
Statement stmt = null;
String sql = "Select * from Customers where CustEmail='" + un + "' and CustPasswd='" + pw  + "'";
try {
	
	Class.forName("com.mysql.jdbc.Driver").newInstance();
	conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/travelexperts","root","root");
	stmt = conn.createStatement();
	ResultSet rs = stmt.executeQuery(sql);
	if (rs.next())
	{
		
		firstName = rs.getString(2);
		lastName = rs.getString(3);
		address = rs.getString(4);
		city = rs.getString(5);
		prov = rs.getString(6);
		postal = rs.getString(7);
		country = rs.getString(8);
		homePhone = rs.getString(9);
		busPhone = rs.getString(10);
		email = rs.getString(10);
		password = rs.getString(13);
		session = request.getSession();
        session.setAttribute("username",firstName);
	
	}
	else {
		response.sendRedirect("login.jsp");
		
	}
}catch(Exception e) {
	e.printStackTrace();
}
finally {
conn.close();
stmt.close();
}

%>

<div class="col4 first">
 <h2>Hello <%=session.getAttribute("username") %></h2>
</div>
<div class="col8">
<ul>
	<li><%=firstName %> <%=lastName %></li>
	<li><%= address%></li>
	<li><%= city%>, <%=prov %></li>
	<li><%= country%>, <%=postal %></li>
	<li>Home: <%= homePhone%></li>
	<li>Bus: <%= busPhone %></li>
	<li><%= email%></li>

</ul>
<div id="accordion">
<h3>Edit Info >></h3>
<div>
<form action="formHandler.jsp" action="get">
<input type="text" name="fname" id="fname" />
<input type="text" name="lname" id="lname" />
<input type="text" name="caddress" id="caddress" />
<input type="text" name="ccity" id="ccity" />
<select name="cprov">
<option value="choose">Select Province</option>
<option value="AB">Alberta</option>
<option value="BC">British Columbia</option>
<option value="SK">Saskatchewan</option>
<option value="MB">Manitoba</option>
<option value="ON">Ontario</option>
<option value="QC">Quebec</option>
<option value="NB">New Brunswick</option>
<option value="NS">Nova Scotia</option>
<option value="PI">Prince Edward Island</option>
<option value="NL">Newfoundland/Labrador</option>
</select>
<input type="text" name="cpostal" id="cpostal" />
<input type="text" name="ccountry" id="ccountry" />
<input type="tel" name="chomephone" id="chomphone" />
<input type="tel" name="cbusphone" id="cbusphone" />
<input type="email" name="cemail" id="cemail" />
<input type="password" name="cpasswd" id="passwd" />
<input type="password" name="confirmPasswd" id="confirmPasswd" />
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</div>

</div>
</div>
<div class="row-end"></div>
<h2>Booking Info:</h2>
<table>
<tr><th>Booking Number</th><th>Booking Date</th><th>Travellers Count</th></tr>
<% 
//Mike Earl
//declare variables for customer info that will be used in the HTML;
String sqlb = "Select * from Bookings b, Customers c where c.CustEmail = '" + un + "' and c.CustPasswd = '" + pw + "' and b.CustomerId = c.CustomerId";
try {
	
	Class.forName("com.mysql.jdbc.Driver").newInstance();
	conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/travelexperts","root","root");
	stmt = conn.createStatement();
	ResultSet rsb = stmt.executeQuery(sqlb);
	while(rsb.next())
	{	
		bookingDate = rsb.getString(2);
		bookingNo = rsb.getString(3);
		travellerCount = rsb.getString(4);
		out.println( "<tr><td>" + bookingNo + "</td><td>" + bookingDate + "</td><td>" + travellerCount + "</td></tr>");
	}	
}catch(Exception e) {
	e.printStackTrace();
}
finally {
conn.close();
stmt.close();
}

%>
</table>

<!-- END Main -->
<!-- the row-end div is to take care of the floating issue -->
<div class="row-end"></div>
<div id="push"></div>
</div><!-- END OF Spacer -->
<jsp:include page="footer.jsp" />